package controlSoftware.MockDataIn;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import controlSoftware.mainUI;
import controlSoftware.userThread.Device;
import controlSoftware.userThread.SensorData;

public class MockDataSource {
	int t = 0;
	SensorData data = null;
	Queue<SensorData> mockData = new ConcurrentLinkedQueue<SensorData>();
	final static String FILEPATH = "sampleData/Jina.txt";

	public MockDataSource(DataSourceType src) {
		switch (src) {
		case STATIC:
			for (int i = 1; i <= 100; i++) {
				//data = new SensorData(10, 10, 10, 0, 0, 0);
				//mockData.add(data);
			}
			;
			break;
		case FILE:
			// only supports x,y,z for now
		{
			try {
				FileInputStream fstream = new FileInputStream(FILEPATH);
				InputStreamReader dataIn = new InputStreamReader(fstream);
				BufferedReader reader = new BufferedReader(dataIn);

				String[] data;
				String line;

				Device testObj = new Device (1, "Jina", "Changgggg");
				mainUI.ActiveObjs[0]= testObj;
				
				while ((line = reader.readLine()) != null) {
					data = line.split("\\,");
					SensorData dataObj = new SensorData(
							Double.parseDouble(data[0]),
							Double.parseDouble(data[1]),
							Double.parseDouble(data[2]), 0, 0, 0, testObj);
					mockData.add(dataObj);
				}
			} catch (Exception e) {
				System.out.println("File: "+ FILEPATH + "\n" + e.getMessage());
			}

		}
			;
			break;
		}
	}

	public SensorData getNextMockData() {
		return mockData.poll();
	}

}
